#include <stdio.h>
#include <stdlib.h>

#include "node.h"

/* Creation */
node* n_new()
{
	node *This = malloc(sizeof(node));
	if (!This) return 0;
	n_init(This);
	This->destroy = n_destroy;
	return This;
}

/* Name handling */
	/* set name */
void n_nset(node *This, char* new_name)
{
	This->name = new_name;
}
	/* get name */
char* n_nget(node *This)
{
	return (This->name);
}

/* Position */
	/* Set x */
void n_setx(node *This, int nx)
{
	This->x = nx;
}
	/* Set y */
void n_sety(node *This, int ny)
{
	This->y = ny;
}
	/* Get x */
int n_getx(node *This)
{
	return (This->x);
}
	/* Get y */
int n_gety(node *This)
{
	return (This->y);
}

/* Display */
void n_print (node *This)
{
	printf("name: %s\n", This->get_name(This));
	printf("x: %d, y: %d\n", This->getx(This), This->gety(This));
	printf("\n");
}

/* Init */
static void n_init(node *This)
{
	This->set_name = n_nset;
	This->get_name = n_nget;
	This->setx     = n_setx;
	This->sety     = n_sety;
	This->getx     = n_getx;
	This->gety     = n_gety;
	This->print    = n_print;
	This->destroy  = n_destroy;
	This->name     = "Untitled";
}

/* Destroy */
void n_destroy(node *This)
{
	free(This);
}